﻿using System;
using Microsoft.Devices;
using Microsoft.Phone.Controls;

namespace Pomodoro
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
            DataContext = App.ViewModel;

            this.BackKeyPress += (s, e) =>
            {
                if (App.ViewModel.SettingsVisible)
                {
                    App.ViewModel.SettingsVisible = false;
                    this.ApplicationBar.IsVisible = true; // http://stackoverflow.com/questions/5334574/applicationbariconbutton-is-null
                    e.Cancel = true;
                }
            };
        }

        private void WindUpWheel(object sender, EventArgs e)
        {
            this.Wheel.WindUpWheel();
        }

        private void ShowSettings(object sender, EventArgs e)
        {
            if (!App.ViewModel.SettingsVisible)
            {
                App.ViewModel.SettingsVisible = true;
                this.ApplicationBar.IsVisible = false;
                if (App.ViewModel.Vibrate)
                {
                    var vc = VibrateController.Default;
                    vc.Start(TimeSpan.FromMilliseconds(5));
                }
            }
        }


    }
}